<template>
  <div class="app-container">
    <!-- 添加或修改项目基础信息管理对话框 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">

      <!-- <el-form-item label="框架编号" prop="projectNo">
        <el-input v-model="queryParams.params['projectNo']" placeholder="请输入框架编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="订单编号" prop="projectNo">
        <el-input v-model="queryParams.projectNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="需求日期">
        <el-date-picker v-model="dateRange" style="display: flex;" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="制单人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="请输入制单人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="业务员" prop="salesmanName">
        <el-input v-model="queryParams.params['salesmanName']" placeholder="请输入业务员" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否自制" prop="isdo">
        <el-select v-model="queryParams.isdo" placeholder="是否自制" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.isdo" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <!--<el-button slot="reference" type="success" plain icon="el-icon-finished" size="mini" :disabled="multiple" style="margin-left:10px;"
        >批量提交</el-button>-->
      </el-form-item>
    </el-form>
    <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading" @sort-change="handleSortChange">
      <!--<el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>-->
      <el-table-column sortable label="订单编号" align="center" prop="projectNo" />
      <el-table-column sortable label="需求日期" align="center" prop="deliveryTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
      <el-table-column sortable label="产品状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.goods_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column sortable label="发货状态" align="center" prop="isfahuo">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yifahuo_status" :value="scope.row.isfahuo" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="订单数量" prop="orderCount" />
      <el-table-column sortable align="center" label="库存锁定数量" prop="lockCount" />
      <el-table-column sortable align="center" label="发货数量" prop="fahuoCount" />
      <el-table-column sortable align="center" label="剩余发货数量" prop="fahuoShengyu" />
      <el-table-column sortable align="center" label="产品名称" prop="goodsName" show-overflow-tooltip />
      <el-table-column sortable align="center" label="产品型号" prop="model" show-overflow-tooltip />
      <el-table-column sortable align="center" label="产品单位" prop="unit" />
      <el-table-column sortable align="center" label="销售单价" prop="goodsUnitPrice" />
      <el-table-column sortable align="center" label="制单人" prop="createBy" />
      <el-table-column sortable align="center" label="业务员" prop="order.salesmanName" />
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button @click="fahuoDetail(scope.row)" icon="el-icon-view" size="mini" type="text">
            发货详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <yiFahuoBySale-list ref="yiFahuoBySaleListForm" @ok="getList"></yiFahuoBySale-list>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
  import {
    addAction,
    deleteAction,
    downloadFile,
    getAction,
    getById
  } from '@/api/manage'
  import {
    listSale
  } from "@/api/develop/goodsSale";
  import YiFahuoBySaleList from "@/views/develop/goodsSale/YiFahuoBySaleList";

  export default {
    name: "FahuoGoodsaleList",
    dicts: ['isdo', 'sale_state', 'goods_status', 'yifahuo_status'],
    components: {
      YiFahuoBySaleList
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "订单产品明细",
        // 是否显示弹出层
        open: false,
        // 显示搜索条件
        showSearch: true,
        // 表单参数
        form: {},
        proId: "",
        proStatus: "",
        columns: [],
        total: 0,
        // 表单校验
        rules: {},
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          params: {},
          id: null,
          code: null,
          projectNo: null,
          goodsName: null,
          goodsCode: null,
          salesmanName: null,
          model: null,
          brand: null,
          isdo: null,
          remark: null,
          projectId: null,
          createBy: null,
          orderByColumn: "create_time",
          isAsc: "desc"
        },
        url: {
          list: '/goodsSale/goodsSale/list',
          getById: '/projectBaseInfo/projectBaseInfo/',
          exportData: '/goodsSale/goodsSale/exportData',
        },
      };
    },
    created() {
      //this.handleQuery();
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    methods: {
      fahuoDetail(row) {
        this.$refs.yiFahuoBySaleListForm.yiFahuoBySaleShow(row);
      },
      getList() {
        this.loading = true;
        listSale(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.columns = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
       /** 排序触发事件 */
        handleSortChange(column, prop, order) {
          this.queryParams.orderByColumn = column.prop;
          this.queryParams.isAsc = column.order;
          this.handleQuery();
        },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.params = {}
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      reset() {
        this.form = {
          id: null,
          code: null,
          projectNo: null,
          goodsName: null,
          goodsCode: null,
          salesmanName: null,
          model: null,
          brand: null,
          isdo: null,
          remark: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null
        };
        this.resetForm("form");
      },
    }
  };
</script>
